<template>
  <div class="fittedCurve">
    <!-- 图形 -->
    <el-checkbox-group 
      v-model="checkList" 
      @change="handleChange"
      style="margin:20px 0 40px 20px;">
      <el-checkbox
        :disabled="checkList.length === 1 && checkList.indexOf('曲线') > -1"
        :label="$t('page.curve')"
      />
      <el-checkbox
        :disabled="checkList.length === 1 && checkList.indexOf('拟合') > -1"
        :label="$t('page.fitting')"
      />
    </el-checkbox-group>
    <linePointDiagram
      :value="originalData"
      :title="title"
    ></linePointDiagram>
  </div>
</template>

<script>
import linePointDiagram from '@/commonPage/linePointDiagram'
import { formatData } from '@/commonPage/linePointDiagram/formatData'

export default {
  props: {
    originalData1: {
      type: Array,
      default: () => [],
    },
    originalData2: {
      type: Array,
      default: () => [],
    },
    // echarts的标题
    title: {
      type: String,
      default: "",
    },
    resultValue: {
      type: Object,
      default: () => {},
    },
    // 标识线数据
    dissociation: {
      type: Array,
      default: () => [0],
    },
  },
  components: {
    linePointDiagram
  },
  data() {
    return {
      originalData: {}, // 处理好的数据
      checkList: ["曲线", "拟合"],
    };
  },
  methods: {
    handleChange(value) {
      if(value.length === 2) {
        this.originalData = {
          ...formatData(this.originalData1[0]),
          ...formatData(this.originalData2[0], '拟合'),
        }
      } else if(value.includes('拟合')) {
        this.originalData = {
          ...formatData(this.originalData2[0], '拟合'),
        }
      } else {
        this.originalData = {
          ...formatData(this.originalData1[0]),
        }
      }
    },
    // 返回生成图片base64
    shotImg(url) {
      this.$emit("showImg", url);
    },
  },
  watch: {
    originalData1: {
      handler() {
        this.$nextTick((value) => {
          if(value && value.length < 1) return
          this.handleChange(this.checkList)
        });
      },
      deep: true,
      immediate: true
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
    background-color: #409eff;
    border-color: #409eff;
  }
  .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    border-color: #fff;
  }
  .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #409eff;
  }
}
.fittedCurve {
  display: flex;
  flex-direction: column;
}
</style>
